-
Notifications
You must be signed in to change notification settings - Fork 14
#201 | Enhanced tenanted and untenanted associations #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
#201 | Enhanced tenanted and untenanted associations #205
Conversation
|
Hi! Thanks for opening this draft. I'll dig in and review as soon as I can find time! |
|
Sorry, it's been a busy week. I will definitely get to this soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the right direction. I know in the original description I suggested something like .where(tenant_id: tenant) but that was meant to be illustrative.
The general problem that I personally need to solve is for a model where the tenant ID is not in the database.
|
Hmm. Please ignore my review for now, I'm still wrapping my head around the problem and this approach. |
flavorjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good start on a very complex feature. I'm not at all sure how belongs_to might be implemented, but this seems like a promising direction for the has_one and has_many side of the association.
| test "has_one automatically scopes by tenant_id" do | ||
| TenantedApplicationRecord.create_tenant("foo") do | ||
| user = User.create!(email: "[email protected]") | ||
| Announcement.create!(message: "Foo announcement", tenant_id: "foo", user: user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally I'd like to be able to do this in an untenanted scope, but it looks like AR does some validation that requires a tenanted connection ...
I'd also like to be able to do this without explicitly setting the tenant id in Announcement, that is:
Announcement.create! user: usershould set the tenant column automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do we want to set this tenant column automatically even for untenanted ones?
For this specific case, User is tenanted by TenantedApplicationRecord and Annoucement is using SharedApplicationRecord
I can't find a simple way to manage the ActiveRecord call to the untenanted ones unless we transform them into Subtenanted ones 🤔
@flavorjones Thanks for the awesome feedback, I'll try to get back to work here later this week! |
3895dd5 to
be86ddc
Compare
|
Hey @flavorjones |
feature: Easy associations between tenanted and untenanted models
Checklist:
has_onehas_manybelongs_to